// 登录页

module.exports = (req, res) => {
    // res.send('登录页');
    // console.log(req.body);
    model.User.findOne({
        username: req.body.username
    }).then(result => {
        // console.log(result);
        if (!result) {
            res.send({
                code: "200",
                status: "406", //406:用户不存在;405:用户已存在
                msg: "用户名或密码错误"
            })
        } else {
            if (req.body.password == result.password) {
                var token = jwt.sign({   //加密内容
                    data: result.userId,
                    iat: Math.floor(Date.now() / 1000) - 30,
                    exp: Math.floor(Date.now() / 1000) + (24*60 * 60),

                },
                    't-o_ken' //加盐 
                );
                // console.log(token);
                let tokenObj = {
                    fskl:token.split('.')[0],
                    sswr:token.split('.')[1],
                    ttnk:token.split('.')[2],
                    wznn:"8iOiJ1cX8W9u2VUzI1NiIsInR5ydG9rZW4x"
                }
                res.send({
                    code: "200",
                    status: "405", //406:用户不存在;405:用户已存在
                    msg: "登录成功",
                    tokenObj:tokenObj
                })
            } else {
                res.send({
                    code: "200",
                    status: "406", //406:用户不存在;405:用户已存在
                    msg: "用户名或密码错误"
                })
            }

        }
    })
}